//
// Created by geoffrey on 24-12-15.
//

#include "g.h"
auto sign = [](double x) { return (x >= 0) ? 1 : -1; };
double g(double tao ,double tao_max){
  if(std::abs(tao) <= tao_max){
    return tao;
  }
  else{
    double vartheta = 0.9;
    double W = (1 - vartheta) * tao_max;
    return vartheta * tao_max * sign(tao) + W * sign(tao) * tanh((std::abs(tao) - vartheta * tao_max)/W);
  }
  }